package com.example.myproject;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.example.myproject", appContext.getPackageName());
    }

    /**
     * 测试 java中的闭包实现
     */
    @Test
    public void testCloasure() {
//        AClosureImpl ac = new AClosureImpl();
//        AClosureImpl.ClosureImpl aImpl = ac.new ClosureImpl();
//        aImpl.eats();
    }

    /**
     * 一般的代理方式来实现  对象创建的过程
     * <p>
     * 闭包会能够直接使用  对象.new  操作
     *
     * @return
     */
    public ClosureInf getClosure() {
        return new San();
    }

    private class San implements ClosureInf {
        @Override
        public void eats() {

        }
    }

    interface ClosureInf {
        void eats();
    }
}
